//
//  RegisterFirstViewController.m
//  Snigger
//
//  Created by Young on 16/8/19.
//  Copyright © 2016年 Smile. All rights reserved.
//

#import "RegisterFirstViewController.h"

#import "RegisterSecondViewController.h"
#import <SMS_SDK/SMSSDK.h>

#define kBackgroundColor [UIColor colorWithRed:236 / 256.0 green:237 / 256.0 blue:240 / 256.0 alpha:1.0]

#define kButtonColor [UIColor colorWithRed:0 / 256.0 green:189 / 256.0 blue:237 / 256.0 alpha:1.0]

@interface RegisterFirstViewController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UIButton *getVoiceButton;
@property (weak, nonatomic) IBOutlet UIButton *getSMSButton;
@property (weak, nonatomic) IBOutlet UIButton *checkButton;

@end

@implementation RegisterFirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"Enter your phone number";
    self.view.backgroundColor = kBackgroundColor;
    _getSMSButton.layer.cornerRadius = 5;
    _getVoiceButton.layer.cornerRadius = 5;
    _checkButton.tag = 101;
    [_checkButton setImage:[UIImage imageNamed:@"unchecked_checkbox"] forState:(UIControlStateNormal)];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    RegisterSecondViewController *registerSecondVC = [[RegisterSecondViewController alloc] init];
    [self.navigationController pushViewController:registerSecondVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)getVoiceAuthenticationCodeClicked:(id)sender {
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodVoice phoneNumber:_phoneTextField.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (!error) {
            NSLog(@"获取验证码成功");
            RegisterSecondViewController *registerSecondVC = [[RegisterSecondViewController alloc] init];
            [self.navigationController pushViewController:registerSecondVC animated:YES];
        } else {
            NSLog(@"错误信息：%@",error);
            
        }
    }];

}

- (IBAction)getSMSVerificationCodeClicked:(id)sender {
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:_phoneTextField.text zone:@"86" customIdentifier:nil result:^(NSError *error) {
        if (!error) {
            NSLog(@"获取验证码成功");
            RegisterSecondViewController *registerSecondVC = [[RegisterSecondViewController alloc] init];
            [self.navigationController pushViewController:registerSecondVC animated:YES];
        } else {
            NSLog(@"错误信息：%@",error);
        }
    }];
}

- (IBAction)checkClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
    if (button.tag == 101) {
        [_checkButton setImage:[UIImage imageNamed:@"checked_checkbox"] forState:(UIControlStateNormal)];
        if ([_phoneTextField.text length] == 11) {
            [_getSMSButton setBackgroundColor:kButtonColor];
            [_getVoiceButton setBackgroundColor:kButtonColor];
        }
        button.tag = 102;
    } else {
        [_checkButton setImage:[UIImage imageNamed:@"unchecked_checkbox"] forState:(UIControlStateNormal)];
        _getVoiceButton.backgroundColor = [UIColor lightGrayColor];
        _getSMSButton.backgroundColor = [UIColor lightGrayColor];
        button.tag = 101;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
